package com.mysmartphone.views;

import java.util.ArrayList;
import android.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.mysmartphone.adapter.PhoneListAdapter;

import com.mysmartphone.vistas.R;
import com.mysmartphone.vo.Phone;

public class SearchFragment extends Fragment  {
	
	private ArrayList <Phone>listPhone;
	@Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.main_list, container, false);
        ListView listView  = (ListView) rootView.findViewById(R.id.list);
                 
        ArrayList<Phone>  listaMainRowItem = new ArrayList<Phone>();

        Bundle bundle = getArguments();

        listPhone =(ArrayList<Phone>) bundle.getSerializable("listPhone");
                
        final PhoneListAdapter adapter = new PhoneListAdapter(rootView.getContext(), listPhone);
        listView.setAdapter(adapter);	  
        
	        listView.setOnItemClickListener(new OnItemClickListener() {
	    			
				@Override
				public void onItemClick(AdapterView<?> arg0, View view, int position,
						long indexItem) {
					  
					  MainActivity mainActivity = (MainActivity) getActivity();
					  ArrayList<Phone>auxLista = new ArrayList<Phone>();
					  auxLista.add(listPhone.get(position));
					  mainActivity.showView(6, auxLista);
				}	
	        	
	    	});
       
        return rootView;
    }
}
